package com.woniuxy.three.pms.vip.controller;

import com.woniuxy.three.pms.bean.VipBean;
import com.woniuxy.three.pms.util.Msg;
import com.woniuxy.three.pms.vip.service.IVipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ProjectName: Pms
 * @Package: com.woniuxy.three.pms.vip.controller
 * @ClassName: VipController
 * @Author: 12092
 * @Description: VIP 的接口
 * @Date: 2019/6/28 9:45
 * @Version: 1.0
 */
@Controller
public class VipController {


    @Autowired
    private IVipService vipService;

    /**
     * @Method modifyVipPreferential
     * @Author Capiudor
     * @Version  1.0
     * @Description 设置VIP的折扣优惠和升级条件
     * @Param: vip
     * @Return com.woniuxy.three.pms.util.Msg
     * @Exception
     * @Date 2019/6/28 10:27
     */
    @RequestMapping(value = "/vip",method = RequestMethod.PUT)
    @ResponseBody
    public Msg modifyVipPreferential(@RequestBody VipBean vip){
    	System.out.println(vip);
        boolean modifyResult = vipService.modifyVipPreferential(vip);
        if (modifyResult){
            return Msg.success();
        }
        return Msg.fail();
    }


    /**
     * @Method findAllVip
     * @Author Capiudor
     * @Version  1.0
     * @Description 查询所有的会员等级
     * @Param:
     * @Return com.woniuxy.three.pms.util.Msg
     * @Exception
     * @Date 2019/6/28 10:26
     */
    @RequestMapping(value = "/vip",method = RequestMethod.GET)
    @ResponseBody
    public Msg findAllVip(){
        List<VipBean> list = vipService.findAllVip();
        if (!list.isEmpty()){
            return Msg.success().add("list",list);
        }
        return Msg.fail();
    }

    /**
     * @Method addVip
     * @Author Capiudor
     * @Version  1.0
     * @Description  新增VIP等级
     * @Param: vipBean
     * @Return com.woniuxy.three.pms.util.Msg
     * @Exception
     * @Date 2019/6/28 10:25
     */
    @ResponseBody
    @RequestMapping(value = "/vip",method = RequestMethod.POST)
    public Msg addVip(@RequestBody VipBean vipBean){
        boolean addResult = vipService.addVip(vipBean);
        if (addResult){
            return Msg.success();
        }
        return Msg.fail();
    }

    /**
     * @Method delVip
     * @Author Capiudor
     * @Version  1.0
     * @Description 删除会员等级
     * @Param: vId
     * @Return com.woniuxy.three.pms.util.Msg
     * @Exception
     * @Date 2019/6/28 10:26
     */
    @ResponseBody
    @RequestMapping(value = "/vip",method = RequestMethod.DELETE)
    public Msg delVip(@RequestParam("id")Integer vId){
        boolean delResult = vipService.delVip(vId);
        if (delResult){
            return Msg.success();
        }
        return Msg.fail();
    }
    
    @ResponseBody
    @GetMapping("/vip/{id}")
    public VipBean findById(@PathVariable("id")Integer id) {
    	return vipService.findById(id);
    }
}
